<!-- HTML header for doxygen 1.8.8-->
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- For Mobile Devices -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8" />
    <meta name="generator" content="Doxygen 1.8.15" />
    <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
    <title>DJI Onboard SDK: osdk-core/platform/linux/inc/linux_serial_device.hpp Source File</title>
    <!-- <link href="tabs.css" rel="stylesheet" type="text/css"/> -->
    <script type="text/javascript" src="dynsections.js"></script>
    <link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
    <link href="doxygen.css" rel="stylesheet" type="text/css" />
    <link href="customdoxygen.css" rel="stylesheet" type="text/css"/>
    <link href='https://fonts.googleapis.com/css?family=Roboto+Slab' rel='stylesheet' type='text/css'>
    <link rel="shortcut icon" href="favicon.png" type="image/x-icon" />
    <link rel="stylesheet" href="bootstrap.min.css">
    <link href="jquery.smartmenus.bootstrap.css" rel="stylesheet">
    <link rel="stylesheet" href="bootstrap-theme.css">
    <script src="bootstrap.min.js"></script>
    <link href="jquery.smartmenus.bootstrap.css" rel="stylesheet">
    <!-- SmartMenus jQuery plugin -->
    <script type="text/javascript" src="jquery.smartmenus.min.js"></script>
    <!-- SmartMenus jQuery Bootstrap Addon -->
    <script type="text/javascript" src="jquery.smartmenus.bootstrap.min.js"></script>
    <style>
        .has-submenu {
            position: relative;
        }
        #main-nav {
            margin-top: 60px;
        }
    </style>
</head>
<body>
    <nav id="site-header" class="site-header navbar">
        <div class="container">
            <div class="navbar-header"><a href="/" class="logo"><img src="dji-logo@2x.png">Developer</a></div>
            <div id="header-navbar" class="collapse navbar-collapse">
                <ul class="nav navbar-nav">
                    <li><a href="/mobile-sdk">Mobile SDK</a></li>
                    <li><a href="/ux-sdk">UX SDK</a></li>
                    <li><a href="/onboard-sdk">Onboard SDK</a></li>
                    <li><a href="/payload-sdk">Payload SDK</a></li>
                    <li><a href="/windows-sdk">Windows SDK</a></li>
                </ul>
                <ul v-cloak="" v-show="!loggedIn" class="nav navbar-nav navbar-right nav-user">
                    <li><a
                            href="https://account.dji.com/login?appId=dji_sdk&backUrl=https%3A%2F%2Fdeveloper.dji.com%2Fuser&locale=en_US">Login</a>
                    </li>
                    <li><a href="https://account.dji.com/register?appId=dji_sdk&backUrl=https%3A%2F%2Fdeveloper.dji.com%2Fuser&locale=en_US"
                            class="head-cta">Register</a></li>
                </ul>
                <ul v-cloak="" v-show="loggedIn" class="nav navbar-nav navbar-right nav-user">
                    <li class="hovedown"><a href="javascript:void(0);" class="hovedown-toggle"><i
                                class="fa fa-user"></i></a>
                        <ul class="hovedown-menu hovedown-menu-right">
                            <li><a href="/user">User Center</a></li>
                            <li><a href="javascript:void(0);" v-on="click: logout">Logout</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </nav>
    <div data-offset-top="60" data-spy="affix" class="sub-nav">
        <div class="container">
            <h1 class="logo">Onboard SDK</h1>
            <nav><a href="/onboard-sdk">Overview</a><a href="/onboard-sdk/documentation">Documentation</a><a
                    href="/onboard-api-reference/index.html" class="active">API Reference</a><a
                    href="/onboard-sdk/downloads">Downloads</a>
            </nav>
        </div>
    </div>
    <!--<nav class="navbar navbar-default" role="navigation">-->
    <!--<div class="container">-->
    <!--<div class="navbar-header">-->
    <!--<a href="#" class="navbar-left"><img src="dji_logo_gray_small.png" alt="DJI OSDK API Documentation" width="32px"/></a>-->
    <!--<a class="navbar-brand" href="index.html">ONBOARD SDK 3.3</a>-->
    <!--</div>-->
    <!--</div>-->
    <!--</nav>-->
    <div id="top">
        <!-- do not remove this div, it is closed by doxygen! -->
        <div class="content" id="content">
            <div class="container">
                <div class="row">
                    <div class="col-sm-12 panel " style="padding-bottom: 15px;">
                        <div style="margin-bottom: 15px;">
                            <!-- end header part --><!-- Generated by Doxygen 1.8.15 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_95d02babf7f2c2cbb8138434e234b0a4.html">osdk-core</a></li><li class="navelem"><a class="el" href="dir_50faeb5d8d1628bfd79a767c77d47f2b.html">platform</a></li><li class="navelem"><a class="el" href="dir_46d8e2746c43089a4f7a5f7f15101a6a.html">linux</a></li><li class="navelem"><a class="el" href="dir_bd0bc0336deaf85967edaa654261a041.html">inc</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">linux_serial_device.hpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="linux__serial__device_8hpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;</div><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;<span class="preprocessor">#ifndef LINUXSERIALDEVICE_H</span></div><div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;<span class="preprocessor">#define LINUXSERIALDEVICE_H</span></div><div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;</div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;<span class="preprocessor">#include &lt;cstring&gt;</span></div><div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;<span class="preprocessor">#include &lt;fcntl.h&gt;</span></div><div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;<span class="preprocessor">#include &lt;termios.h&gt;</span></div><div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;<span class="preprocessor">#include &lt;unistd.h&gt;</span></div><div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;<span class="preprocessor">#include &lt;sys/select.h&gt;</span></div><div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;</div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;<span class="preprocessor">#include &quot;dji_hard_driver.hpp&quot;</span></div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;</div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespaceDJI.html">DJI</a></div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;{</div><div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;</div><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;<span class="keyword">namespace </span>OSDK</div><div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;{</div><div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;</div><div class="line"><a name="l00056"></a><span class="lineno"><a class="line" href="classDJI_1_1OSDK_1_1LinuxSerialDevice.html">   56</a></span>&#160;<span class="keyword">class </span><a class="code" href="classDJI_1_1OSDK_1_1LinuxSerialDevice.html">LinuxSerialDevice</a> : <span class="keyword">public</span> HardDriver</div><div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;{</div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;<span class="keyword">public</span>:</div><div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;  <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span> BUFFER_SIZE = 2048;</div><div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;</div><div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;<span class="keyword">public</span>:</div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;  <a class="code" href="classDJI_1_1OSDK_1_1LinuxSerialDevice.html#a8bdb4069f8658bc6bf4c9e1c22aa9c63">LinuxSerialDevice</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* device, uint32_t baudrate);</div><div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;  ~<a class="code" href="classDJI_1_1OSDK_1_1LinuxSerialDevice.html">LinuxSerialDevice</a>();</div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;</div><div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;  <span class="keywordtype">void</span> init();</div><div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;  <span class="keywordtype">bool</span> getDeviceStatus();</div><div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;</div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;  <span class="keywordtype">void</span> <a class="code" href="classDJI_1_1OSDK_1_1LinuxSerialDevice.html#a73ec219df14ded200d5a89b1c0ecca19">setBaudrate</a>(uint32_t baudrate);</div><div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;  <span class="keywordtype">void</span> setDevice(<span class="keyword">const</span> <span class="keywordtype">char</span>* device);</div><div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;</div><div class="line"><a name="l00073"></a><span class="lineno"><a class="line" href="classDJI_1_1OSDK_1_1LinuxSerialDevice.html#ae8024ecb6b46e647446cdb68de98bc29">   73</a></span>&#160;  <span class="keywordtype">int</span> <a class="code" href="classDJI_1_1OSDK_1_1LinuxSerialDevice.html#ae8024ecb6b46e647446cdb68de98bc29">checkBaudRate</a>(uint8_t (&amp;buf)[BUFFER_SIZE])</div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;  {</div><div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;    <span class="keywordflow">return</span> _checkBaudRate(buf);</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;  }</div><div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;  <span class="keywordtype">int</span> setSerialPureTimedRead();</div><div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;  <span class="keywordtype">int</span> unsetSerialPureTimedRead();</div><div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;  <span class="keywordtype">int</span> serialRead(uint8_t* buf, <span class="keywordtype">int</span> len);</div><div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;</div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;  <span class="keywordtype">size_t</span> <a class="code" href="classDJI_1_1OSDK_1_1LinuxSerialDevice.html#a8d049404301807f9b270b85dad740d5a">send</a>(<span class="keyword">const</span> uint8_t* buf, <span class="keywordtype">size_t</span> len);</div><div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;  <span class="keywordtype">size_t</span> readall(uint8_t* buf, <span class="keywordtype">size_t</span> maxlen);</div><div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;</div><div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;  DJI::OSDK::time_ms <a class="code" href="classDJI_1_1OSDK_1_1LinuxSerialDevice.html#a0acb5e77c1f9dd0ab64dab66c4b1e43f">getTimeStamp</a>();</div><div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;</div><div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;  <span class="keywordtype">void</span> delay_nms(uint16_t time)</div><div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;  {</div><div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;    ;</div><div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;  }</div><div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;</div><div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;<span class="keyword">private</span>:</div><div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;  <span class="keyword">const</span> <span class="keywordtype">char</span>* m_device;</div><div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;  uint32_t    m_baudrate;</div><div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;</div><div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;  <span class="keywordtype">int</span>    m_serial_fd;</div><div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;  fd_set m_serial_fd_set;</div><div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;  <span class="keywordtype">bool</span>   deviceStatus;</div><div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;</div><div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;  <span class="keywordtype">bool</span> _serialOpen(<span class="keyword">const</span> <span class="keywordtype">char</span>* dev);</div><div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;  <span class="keywordtype">bool</span> _serialClose();</div><div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;  <span class="keywordtype">bool</span> _serialFlush();</div><div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;  <span class="keywordtype">bool</span> _serialConfig(<span class="keywordtype">int</span> baudrate, <span class="keywordtype">char</span> data_bits, <span class="keywordtype">char</span> parity_bits,</div><div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;                     <span class="keywordtype">char</span> stop_bits, <span class="keywordtype">bool</span> testForData = <span class="keyword">false</span>);</div><div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;</div><div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;  <span class="keywordtype">int</span> _serialStart(<span class="keyword">const</span> <span class="keywordtype">char</span>* dev_name, <span class="keywordtype">int</span> baud_rate);</div><div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;  <span class="keywordtype">int</span> _serialWrite(<span class="keyword">const</span> uint8_t* buf, <span class="keywordtype">int</span> len);</div><div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;  <span class="keywordtype">int</span> _serialRead(uint8_t* buf, <span class="keywordtype">int</span> len);</div><div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;</div><div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;  <span class="keywordtype">int</span> _checkBaudRate(uint8_t (&amp;buf)[BUFFER_SIZE]);</div><div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;};</div><div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;}</div><div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;}</div><div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;</div><div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;<span class="preprocessor">#endif // LINUXSERIALDEVICE_H</span></div><div class="ttc" id="classDJI_1_1OSDK_1_1LinuxSerialDevice_html_ae8024ecb6b46e647446cdb68de98bc29"><div class="ttname"><a href="classDJI_1_1OSDK_1_1LinuxSerialDevice.html#ae8024ecb6b46e647446cdb68de98bc29">DJI::OSDK::LinuxSerialDevice::checkBaudRate</a></div><div class="ttdeci">int checkBaudRate(uint8_t(&amp;buf)[BUFFER_SIZE])</div><div class="ttdef"><b>Definition:</b> linux_serial_device.hpp:73</div></div>
<div class="ttc" id="classDJI_1_1OSDK_1_1LinuxSerialDevice_html_a8bdb4069f8658bc6bf4c9e1c22aa9c63"><div class="ttname"><a href="classDJI_1_1OSDK_1_1LinuxSerialDevice.html#a8bdb4069f8658bc6bf4c9e1c22aa9c63">DJI::OSDK::LinuxSerialDevice::LinuxSerialDevice</a></div><div class="ttdeci">LinuxSerialDevice(const char *device, uint32_t baudrate)</div><div class="ttdef"><b>Definition:</b> linux_serial_device.cpp:41</div></div>
<div class="ttc" id="classDJI_1_1OSDK_1_1LinuxSerialDevice_html_a73ec219df14ded200d5a89b1c0ecca19"><div class="ttname"><a href="classDJI_1_1OSDK_1_1LinuxSerialDevice.html#a73ec219df14ded200d5a89b1c0ecca19">DJI::OSDK::LinuxSerialDevice::setBaudrate</a></div><div class="ttdeci">void setBaudrate(uint32_t baudrate)</div><div class="ttdef"><b>Definition:</b> linux_serial_device.cpp:102</div></div>
<div class="ttc" id="classDJI_1_1OSDK_1_1LinuxSerialDevice_html_a8d049404301807f9b270b85dad740d5a"><div class="ttname"><a href="classDJI_1_1OSDK_1_1LinuxSerialDevice.html#a8d049404301807f9b270b85dad740d5a">DJI::OSDK::LinuxSerialDevice::send</a></div><div class="ttdeci">size_t send(const uint8_t *buf, size_t len)</div><div class="ttdoc">Start of DJI_HardDriver virtual function implementations.</div><div class="ttdef"><b>Definition:</b> linux_serial_device.cpp:83</div></div>
<div class="ttc" id="classDJI_1_1OSDK_1_1LinuxSerialDevice_html"><div class="ttname"><a href="classDJI_1_1OSDK_1_1LinuxSerialDevice.html">DJI::OSDK::LinuxSerialDevice</a></div><div class="ttdoc">POSIX-Compatible Serial Driver for *NIX platforms.</div><div class="ttdef"><b>Definition:</b> linux_serial_device.hpp:56</div></div>
<div class="ttc" id="namespaceDJI_html"><div class="ttname"><a href="namespaceDJI.html">DJI</a></div><div class="ttdef"><b>Definition:</b> dji_ack.cpp:38</div></div>
<div class="ttc" id="classDJI_1_1OSDK_1_1LinuxSerialDevice_html_a0acb5e77c1f9dd0ab64dab66c4b1e43f"><div class="ttname"><a href="classDJI_1_1OSDK_1_1LinuxSerialDevice.html#a0acb5e77c1f9dd0ab64dab66c4b1e43f">DJI::OSDK::LinuxSerialDevice::getTimeStamp</a></div><div class="ttdeci">DJI::OSDK::time_ms getTimeStamp()</div><div class="ttdoc">Implemented here because ..</div><div class="ttdef"><b>Definition:</b> linux_serial_device.cpp:77</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.8-->
<!-- start footer part -->
</div>
</div>
</div>
</div>
</div>
<hr class="footer"/><address class="footer"><small>
  <footer id="site-footer" class="site-footer">
    <div class="container">
      <div class="foot-nav row">
        <nav class="link-list col-xs-2"><span class="title">SDK</span><a href="/mobile-sdk">Mobile SDK</a><a href="/ux-sdk">UX SDK</a><a href="/onboard-sdk">Onboard SDK</a><a href="/payload-sdk">Payload SDK</a><a href="/windows-sdk">Windows SDK</a></nav>
        <nav class="link-list col-xs-2"><span class="title">Info</span><a href="/products">Products</a></nav>
        <nav class="link-list col-xs-2"><span class="title">Community</span><a href="http://stackoverflow.com/questions/tagged/dji-sdk" target="_blank">Stack Overflow</a><a href="https://www.youtube.com/channel/UCPQwN5xsob8zZGIcDhkYqUA" target="_blank">YouTube</a><a href="https://twitter.com/djidevelopers" target="_blank">Twitter</a></nav>
        <nav class="link-list col-xs-2"><span class="title">Contact Us</span><a href="mailto:dev@dji.com"> dev@dji.com</a></nav>
        <nav class="link-list col-xs-2"><span class="title">Business Cooperation</span><a href="mailto:dev@dji.com"> dev@dji.com</a></nav>
        <nav class="link-list col-xs-2"><span class="title">BILLING</span><a href="mailto:billing-dev@dji.com"> billing-dev@dji.com</a></nav>
      </div>
      <div class="foot-copyright row">
        <div class="col-xs-3 foot-logo"><img src="dji-logo-foot.png"></div>
        <div class="copyright col-xs-7"><span>Copyright © 2018 DJI All Rights Reserved</span><a href="/policies/privacy">Privacy Policy</a><a href="/policies/terms">Terms of Use</a></div>
        <div class="col-xs-2">
          <div class="lang-selector">
            <select dir="rtl" v-model="lang">
              <option value="en">English</option>
              <option value="cn">中文</option>
            </select><i class="fa fa-globe"></i>
          </div>
        </div>
      </div>
    </div>
  </footer>
</small></address>
</body>
<script type="text/javascript" src="doxy-boot.js"></script>
</html>
